package com.hyl.domain.activity.service.discount.impl;

import com.hyl.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import com.hyl.domain.activity.service.discount.IDiscountCalculateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;



/**
 * @author hyl
 * @description 直减
 * @create 2025-06-17 20:30
 */
@Slf4j
@Service("ZJ")
public class ZJCalculateService implements IDiscountCalculateService {


    @Override
    public BigDecimal calculate(String userId, BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {

        String marketExpr = groupBuyDiscount.getMarketExpr();

        // 折扣价格
        BigDecimal deductionPrice = originalPrice.subtract(new BigDecimal(marketExpr));
        // 判断折扣后金额，最低支付1分钱
        if (deductionPrice.compareTo(BigDecimal.ZERO) < 0){
            return new BigDecimal("0.01");
        }
        return deductionPrice;//折扣价格
    }
}
